<template>
  <n-h1>实时风控</n-h1>
  <n-alert v-for="a in alerts" :key="a" type="warning">{{ a }}</n-alert>
  <n-p>净值：{{ nav.toFixed(2) }}</n-p>
  <n-p>最大回撤：{{ (dd * 100).toFixed(2) }}%</n-p>
</template>

<script setup>
import { ref } from 'vue'
const alerts = ref([])
const nav = ref(100000)
const dd = ref(0)

const ws = new WebSocket('ws://localhost:8001/api/market/ws/tick')
ws.onmessage = (ev) => {
  const d = JSON.parse(ev.data)
  if (d.type === 'risk') {
    alerts.value = d.alerts
  } else {
    nav.value = d.nav || nav.value
    dd.value = d.drawdown || dd.value
  }
}
</script>
